<?php

function a_connopen()
{
global $a_LINK;
$a_LINK=mysql_connect(A_DB_HOST,A_DB_USER,A_DB_PASSWORD);
mysql_select_db(A_DB_NAME,$a_LINK); // {echo "ok.";};
}

function a_execsql($sql)
{
global $a_LINK; 
a_connopen();
$res=mysql_query($sql,$a_LINK);
return $res;
}


function connopen()
{
global $LINK;
global $DB_NAME,$DB_USER,$DB_HOST,$DB_PASS;
$LINK=mysql_connect($DB_HOST,$DB_USER,$DB_PASS);
//echo "LINK: $LINK";
mysql_select_db($DB_NAME,$LINK);
}

function execsql($sql)
{
global $LINK;
global $DB_NAME,$DB_USER,$DB_HOST,$DB_PASS;    
connopen();
$res=mysql_query($sql,$LINK);
return $res;
}


function tab_descr($table_name)
{
$sql="DESCRIBE `$table_name`";
$res=execsql($sql);
$tabdescr='';
$j=0;
while ($row=mysql_fetch_assoc($res))
{
$j++;
$tabdescr[$j]=$row;   
}
$c_tabdescr=$j;
return $tabdescr;
}

function execsql_xml($table_name, $sql)
{
$ardescr=tab_descr($table_name);
//print_r($ardescr);
$c_ardescr=count($ardescr);


$res=execsql($sql);
$xmlall="<result>\r\n";
while ($row=mysql_fetch_assoc($res))
{  
    $xmlblock="<row>\r\n";    
    for($j=1;$j<=$c_ardescr;$j++)
    {   $field=$ardescr[$j]['Field'];
        if (isset($row[$field]))
        {
        $xmlblock=$xmlblock. "<".$field.">";
        $xmlblock=$xmlblock. $row[$field]; 
        $xmlblock=$xmlblock."</".$field.">\r\n";
        }
    }
$xmlblock=$xmlblock."</row>\r\n";    
$xmlall=$xmlall.$xmlblock."\r\n";    
//echo "<br><br>";
}
$xmlall=$xmlall."</result>\r\n";
return $xmlall;
} 



?>
